const db = wx.cloud.database()
Page({
  data: {
    msgList: []
  },
  goQun() {
    wx.navigateTo({
      url: 'qun/qun',
    })
  },
  goLookSchool() {
    wx.navigateTo({
      url: 'lookSchool/lookSchool',
    })
  },
  goSchool() {
    wx.switchTab({
      url: '/pages/campus/campus',
    })
  },
  goSay(e) {
    wx.navigateTo({
      url: 'say/say?title=' + e.currentTarget.dataset.title,
    })
  },
  onLoad: function () {
    var that = this ;
    wx.cloud.callFunction({
      name: 'login',
      complete: res => {
        db.collection("user").where({
          _openid: res.result.openid
        }).get({
          success: function (res) {
            if (res.data.length == 0) {
              wx.navigateTo({
                url: '/pages/login/login',
              })
            } else {
              wx.setStorageSync('openid', res.data[0]._openid); //存储openid
              wx.setStorageSync('userId', res.data[0]._id); //存储id
            }
          }
        })
      }
    })
    db.collection("question").where({
      isGongGao: true
    }).get({
      success: function (res) {
        that.setData({
          msgList:res.data
        })
      }
    })
    db.collection("user").count({
      success: function (res) {
        console.log(res)
        that.setData({
          peopleSum:res.total+5000
        })
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "民大新生小助手",
      path:"/pages/index/index"
    }
  }
})